package com.hsp.Demo_02_array;

public class Demo_06 {
    public static void main(String[] args) {
        /*
        数组反转：
        {1， 2， 3， 4， 5， 6} ==> {6, 5, 4, 3, 2, 1}
         */



       /*方式一：
       int[] arr = {1, 2, 3, 4, 5, 6};
       int[] arr2 = new int[arr.length];
        for(int i = 0; i < arr.length; i++){
            arr2[i] = arr[arr.length - 1 -i];
        }
        System.out.print("{");
        for(int i = 0; i < arr2.length; i++){
            System.out.print(arr2[i] + ", ");
        }
        System.out.print("}");*/

        //方式二：
        int[] arr = {1, 2, 3, 4, 5, 6};
        int temp = 0;
        int len = arr.length;

        for(int i = 0; i < len/2; i++){
            temp = arr[i];
            arr[i] = arr[len - 1 - i];
            arr[len - 1 - i] = temp;
        }

        for(int i = 0; i < len; i++){
            System.out.print(arr[i] + " ");
        }

    }
}
